package com.xtedu.examproject.service;

import com.xtedu.examproject.dao.base.SubjectDao;
import com.xtedu.examproject.dao.impl.SubjectDaoImpl;
import com.xtedu.examproject.entity.Subject;
import com.xtedu.examproject.util.PageHelper;

import java.util.List;

public class SubjectService {
    private SubjectDao subjectDao;
    public SubjectService() {
        subjectDao = new SubjectDaoImpl();
    }

    public int insertSubject(Subject subject) throws Exception {
        return subjectDao.insert(subject);
    }

    public int deleteSubject(Subject subject) throws Exception {
        return subjectDao.delete(subject);
    }

    public int updateSubject(Subject subject) throws Exception {
        return subjectDao.update(subject);
    }

    public Subject findSubjectById(int id) throws Exception {
        return subjectDao.findById(id);
    }

    public List<Subject> findAllSubject() throws Exception {
        return subjectDao.findAll();
    }

    public PageHelper findAllSubject(int pageindex, int pagesize) throws Exception {
        return subjectDao.findAllByPage(pageindex, pagesize);
    }

    public PageHelper findSubjectById(int id, int pageindex, int pagesize) throws Exception {
        return subjectDao.findByIdByPage(id, pageindex, pagesize);
    }

    public PageHelper findSubjectByName(String name, int pageindex, int pagesize) throws Exception {
        return subjectDao.findByNameByPage(name,pageindex, pagesize);
    }
}
